package com.seo.textgen.pos.tagger;

import java.io.IOException;
import java.util.List;

import org.apache.commons.io.IOUtils;

public class TreeTagger {

	private TaggedTextParser parser = new TaggedTextParser();

	private static final String TREE_TAGGER_HOME = "/opt/treetagger/";

	public List<TaggedSentence> performPosTagging(String text) throws IOException {
		ProcessBuilder processBuilder = new ProcessBuilder();
		processBuilder.command(TREE_TAGGER_HOME + "/cmd/tree-tagger-russian");
		Process process = processBuilder.start();
		process.getOutputStream().write(text.getBytes("utf-8"));
		process.getOutputStream().close();

		String output = IOUtils.toString(process.getInputStream());

		return parser.parse(text, output);
	}

	public void setEndOfSentenceDetector(EndOfSentenceDetector endOfSentenceDetector) {
		parser.setEndOfSentenceDetector(endOfSentenceDetector);
	}
}
